'use strict';
// 公共方法
(function() {

    var _cc = {}
    _cc.http = function(param) {
        var _this = this;
        var contentType=null;
        if(param.method && (param.method.toUpperCase()=='POST'|| param.method.toUpperCase()=='PATCH' || param.method.toUpperCase()=='DELETE')){
            param.data = typeof param.data =='string'?param.data:JSON.stringify(param.data)
            contentType=param.contentType?param.contentType:"application/json;charset=utf-8"
        }        
        $.ajax({
            type: param.method || 'get',
            url: param.url || '',
            contentType: 'application/json;charset=utf-8',
            dataType: param.type || 'json',
            data: param.data || '',                 
            success: function(res) {
             
                typeof param.success === 'function' && param.success(res);

            },
            error: function(err) {
                console.log(err)
                typeof param.error === 'function' && param.error(err);

            },
            beforeSend:function(){
                try {
                    typeof  param.beforeSend === 'function' && param.beforeSend();
                } catch (error) {
                    
                }
                
               
            },      
            complete:function(){
                typeof  param.complete === 'function' && param.complete();
               
            }
        })
    }
    _cc.parseUrl = function() {
        var url = location.href;
        var i = url.indexOf('?');
        if (i == -1) return;
        var queryStr = url.substr(i + 1);
        var arr1 = queryStr.split('&');
        var arr2 = new Object();
        for (var i in arr1) {
            var ta = arr1[i].split('=');
            arr2[ta[0]] = decodeURI(ta[1]);
        }
        return arr2;
    }

    window['_cc'] = _cc;
})()